<template>
  <div>
    <el-dialog title="岗位内推信息" :visible.sync="dialogFormVisible"  :loading="loading" width="800px">
      <el-form :model="job">
        <el-form-item label="岗位编号" :label-width="formLabelWidth" prop='jobId'>
          <el-input v-model="job.jobId" autocomplete="off" :readonly="readonly"></el-input>
        </el-form-item>
        <el-form-item label="学部编号" :label-width="formLabelWidth" prop='jobPartId'>
          <el-input v-model="job.jobPartId" autocomplete="off" :readonly="readonly"></el-input>
        </el-form-item>
        <el-form-item label="推荐人编号" :label-width="formLabelWidth" prop='jobUserId'>
          <el-input v-model="job.jobUserId" autocomplete="off" :readonly="readonly"></el-input>
        </el-form-item>
        <el-form-item label="岗位名称" :label-width="formLabelWidth" prop='jobName'>
          <el-input v-model="job.jobName" autocomplete="off" :readonly="readonly"></el-input>
        </el-form-item>
        <el-form-item label="岗位公司" :label-width="formLabelWidth" prop='jobCompany"'>
          <el-input v-model="job.jobCompany" autocomplete="off" :readonly="readonly"></el-input>
        </el-form-item>
        <el-form-item label="岗位薪资" :label-width="formLabelWidth" prop='jobSalary'>
          <el-input v-model="job.jobSalary" autocomplete="off" :readonly="readonly"></el-input>
        </el-form-item>
        <el-form-item label="工作地点" :label-width="formLabelWidth" prop='jobAddress'>
          <el-input v-model="job.jobAddress" autocomplete="off" :readonly="readonly"></el-input>
        </el-form-item>
        <el-form-item label="工作经验" :label-width="formLabelWidth" prop='jobExperience'>
          <el-input v-model="job.jobExperience" autocomplete="off" :readonly="readonly"></el-input>
        </el-form-item>
        <el-form-item label="学历要求" :label-width="formLabelWidth" prop='jobEducation'>
          <el-input v-model="job.jobEducation" autocomplete="off" :readonly="readonly"></el-input>
        </el-form-item>
        <el-form-item label="职位详情" :label-width="formLabelWidth" prop='jobDetail'>
          <el-input v-model="job.jobDetail" autocomplete="off" :readonly="readonly"></el-input>
        </el-form-item>
        <el-form-item label="推荐人名称" :label-width="formLabelWidth" prop='jobUserName'>
          <el-input v-model="job.jobUserName" autocomplete="off" :readonly="readonly"></el-input>
        </el-form-item>
        <el-form-item label="推荐人手机" :label-width="formLabelWidth" prop='jobUserPhone'>
          <el-input v-model="job.jobUserPhone" autocomplete="off" :readonly="readonly"></el-input>
        </el-form-item>
        <el-form-item label="推荐人邮箱" :label-width="formLabelWidth" prop='jobUserEmail'>
          <el-input v-model="job.jobUserEmail" autocomplete="off" :readonly="readonly"></el-input>
        </el-form-item>
        <el-form-item label="岗位类型" :label-width="formLabelWidth" prop='jobType'>
          <el-input v-if="job.jobType=='1'" value="学部可见" autocomplete="off" :readonly="readonly"></el-input>
          <el-input v-if="job.jobType=='2'" value="全部可见" autocomplete="off" :readonly="readonly"></el-input>
        </el-form-item>
        <el-form-item label="岗位状态" :label-width="formLabelWidth" prop='jobStatus'>
          <el-input v-if="job.jobStatus=='0'" value="审核中" autocomplete="off" :readonly="readonly"></el-input>
          <el-input v-if="job.jobStatus=='1'" value="已公布" autocomplete="off" :readonly="readonly"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">关 闭</el-button>
        <el-button type="warning" @click="changeConfirm()" v-show="!readonly">修 改</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import {
    getJobByJobId,updateJob
  } from '../../api/job.js'
  export default {
    components: 'Info',
    name: 'Info',
    props: {
      jobId: String,
      show: {
        default: false,
        require: true
      }
    },
    data() {
      return {
        job: {},
        loading: false,
        dialogFormVisible: false,
        formLabelWidth: '150px',
        title: '查看岗位内推信息',
        readonly: true,
        rules: {
          jobId: [{
            required: true,
            message: '岗位编号不得为空',
            trigger: 'blur'
          }],
          jobPartId: [{
            required: true,
            message: '学部编号不得为空',
            trigger: 'blur'
          }],
          jobUserId: [{
            required: true,
            message: '推荐人编号不得为空',
            trigger: 'blur'
          }],
          jobName: [{
            required: true,
            message: '岗位名称不得为空',
            trigger: 'blur'
          }],
          jobCompany: [{
            required: true,
            message: '岗位公司名不得为空',
            trigger: 'blur'
          }],
          jobSalary: [{
            required: true,
            message: '岗位薪资名不得为空',
            trigger: 'blur'
          }],
          jobAddress: [{
            required: true,
            message: '工作地点不得为空',
            trigger: 'blur'
          }],
          jobExperience: [{
            required: true,
            message: '工作经验不得为空',
            trigger: 'blur'
          }],
          jobEducation: [{
            required: true,
            message: '学历要求号不得为空',
            trigger: 'blur'
          }],
          jobDetail: [{
            required: true,
            message: '职位详情号不得为空',
            trigger: 'blur'
          }],
          jobUserName: [{
            required: true,
            message: '推荐人名称不得为空',
            trigger: 'blur'
          }],
          jobUserPhone: [{
            required: true,
            message: '推荐人手机不得为空',
            trigger: 'blur'
          }],
          jobUserEmail: [{
              require: true,
              message: '推荐人邮箱不得为空',
              trigger: 'blur'
            },
            {
              type: 'email',
              message: '请填写正确的邮箱号',
              trigger: ['blur', 'change']
            }
          ],
          jobType: [{
            required: true,
            message: '岗位类型不得为空',
            trigger: 'blur'
          }]
        }
      }

    },
    create() {

    },
    methods: {

      showInfo(jobId) {
        console.log(jobId)
        this.title = "查看岗位内推信息"
        this.readonly = true
        this.fetchData(jobId)
      },
      editInfo(jobId) {
        this.title = "修改岗位内推信息"
        this.readonly = false
        this.fetchData(jobId)
      },
      fetchData(jobId) {
        console.log(jobId)
        this.loading = true
        getJobByJobId(jobId).then((data) => {
          this.job = data.obj
          console.log(data)
          console.log(this.job)
          this.loading = false
          this.dialogFormVisible = true
        })
      },
      changeConfirm(){
        console.log(666)
        this.$confirm('确定提交更改该岗位的信息?').then(()=>{
          //console.log("提交更改")
          console.log(this.job)
          updateJob(this.job).then((data)=>{
            this.$message({
              showClose: true,
              message: '更改成功',
              type: 'success'
            })
          })
          this.dialogFormVisible = false
          location.reload()
        })

      }
    },
    watch: {}

  }
</script>

<style scoped>

</style>
